﻿@page
@model ToolGood.SqlOnline.Pages.Admins.CodeGens.TableTplEditModel
@using ToolGood.WebCommon.Extensions.Mvc;
@{
    Layout = "~/Pages/Shared/_Layout_Edit.cshtml";
    var languageTypeDict = ToolGood.Common.Utils.EnumUtil.GetDescriptions(typeof(ToolGood.SqlOnline.Datas.Enums.EnumTplLanguageType));

    var languageTypeDict2 = new Dictionary<string, string>();
    foreach (var item in languageTypeDict) {
        languageTypeDict2[((ToolGood.SqlOnline.Datas.Enums.EnumTplLanguageType)item.Key).ToString()] = item.Value;
    }
}
@section css{
    <style>
        label.layui-form-label { width: 130px; }
        div.layui-input-block { margin-left: 160px; }
        .layui-form-item { margin-bottom: 3px; }
    </style>
}
<div style="background-color:#f3f3f4;height:100%;overflow:hidden">
    <form id="edit-form" style="width:calc(100% - 550px);height:100%;float:left;overflow-y:scroll">
        <input type="hidden" name="id" value="@Model.TplContent.Id" />
        @Html.AntiForgeryToken()
        <div class="layui-form" lay-filter="form" style="padding: 20px 30px 0 0;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">模板名称<span class="red"> *</span></label>
                    <div class="layui-input-inline">
                        <select class="layui-select" id="txt_Language" name="Language" lay-filter="Language" style="width:150px;">
                            @ToolGood.WebCommon.Extensions.Mvc.ObjectExtensions.ToOption(languageTypeDict2, Model.TplContent.Language))
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="width: calc(100% - 375px); margin-right: 0;">
                    <div class="layui-input-inline" style="width:100%;margin-right:0;">
                        <input type="text" class="layui-input" id="txt_Title" name="Title" value="@Model.TplContent.Title" autocomplete="off">
                    </div>
                </div>
      
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">包名/命名空间</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="txt_Namespace" name="namespace" value="@Model.TplContent.Namespace" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">内容<span class="red"> *</span></label>
                <div class="layui-input-block">
                    <iframe src="./Editors/DotJs" style="width:100%;border:0;height:320px;"></iframe>
                    <div class="layui-form-mid layui-word-aux" style="padding: 5px 0 0!important;">
                        这里支持模板语法，语言：JavaScript。立即进行<a href="javascript:;" onclick="openTpl()" title="测试模板"  >测试模板</a>。
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注 </label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="txt_Comment" name="Comment" value="@Model.TplContent.Comment">
                </div>
            </div>

            <div class="layui-form-item" style="text-align: center; padding-left: 30px;">
                <button type="button" class="layui-btn layui-btn-normal" onclick="save(this);"> &nbsp;&nbsp; 提 交 &nbsp;&nbsp; </button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="closeWindow();"> &nbsp;&nbsp; 关 闭 &nbsp;&nbsp; </button>
            </div>
        </div>

        <div style="height: 5px;"></div>

    </form>

    <div style="width:550px;float:left;height:100%">
        <iframe src="./Editors/DotJs_Table" style="width:100%;border:0;height:99%;"></iframe>
    </div>
    <pre><code id="dotjs">@(Model.TplContent.Content)</code></pre>

</div>
@section js{
    <script>
        function InitEditor() {
            tempSql = $("#dotjs").text();
            setEditor($("#dotjs").text());
        }
        function openTpl() {
            top.window.getLanguageName = $("#txt_Language").val()
            top.window.jstpl = window.getValue();
            var url = "./Editors/DotJsResult?w=800&h=600&type=table";
            openTopWindow("测试模板", url);
        }

        function save(obj) {
            if ($("#txt_Title").val().length == 0) { layer.alert("请输入【模板名称】"); $("#txt_Title").focus(); return; }
            if (window.getValue() == '') { layer.alert("请输入【内容】"); return; }

            $(obj).prop("disabled", true);
            var url = "./Ajax/EditTableTpl";
            var data = $("#edit-form").serializeJson();
            data.content = window.getValue();
            $.adminModePost(url, data, function () {
                closeWindowAndReload();
            }, function (data) {
                $(obj).prop("disabled", false);
                if (data.message) {
                    layer.msg(data.message);
                } else {
                    layer.msg("出错了");
                }
            });
        }

    </script>

}

